package cn.itsource.org.controller;


import cn.itsource.basic.util.AxajResult;
import cn.itsource.basic.util.PageInfo;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.query.ShopQuery;
import cn.itsource.org.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController// @RestController是 一个组合注解     @RestController=@ResponseBody+@Controller
@RequestMapping("/shop")
@Api(tags = "店铺管理所有的接口",description = "店铺接口详细描述")
public class ShopController {


    @Autowired
    private IShopService shopService;



    @PatchMapping//
    public PageInfo<Shop> findPageByQuery(@RequestBody ShopQuery shopQuery){
        return shopService.findAllByQuery(shopQuery);
    }






    @PostMapping// 相当于    @RequestMapping(value = "/shop",method = RequestMethod.POST)
    @ApiOperation(value = "店铺添加或修改",notes = "如果有id就是修改否则就是添加")
    public AxajResult save(@RequestBody Shop shop){
        try {
            shopService.save(shop);
            return new AxajResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AxajResult(false, e.getMessage());
        }
    }





    @DeleteMapping("/{id}")//相当于@RequestMapping(value = "/shop/{id}",method = RequestMethod.DELETE)
    public AxajResult delete(@PathVariable("id") Long id){
        try {
            shopService.delete(id);
            return new AxajResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AxajResult(false, e.getMessage());
        }
    }


    @PostMapping("/settlement")
    public AxajResult settlement(@RequestBody Shop shop){
        try {
            //商家入驻
            shopService.settlement(shop);
            return new AxajResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AxajResult(false, e.getMessage());
        }
    }


}
